BOOT_SHELL="srv.sh"

traverse(){

path=$1

#echo "查找目录："$path;

for file in $path/*; do

  if [ -d $file ]; then

	  if [ $file!=$path  ]; then
	  
	    traverse $file

  	  fi

    else

      filename="$(basename $file)"

      #echo "匹配文件名："$filename

      if [ "$BOOT_SHELL" == "$filename" ]; then

          echo "找到启动脚本："$file

          sh $file $action
	  
	  break

      fi

  fi

done

}


#判断启动参数

case "$1" in
  "start")
    action=start
    ;;
  "stop")
    action=stop
    ;;
  "status")
    action=status
    ;;
  "run")
    action=run
    ;;
   "restart")
    action=restart
    ;;
  *)
    echo "正确用法: $0 [run|start|stop|restart|status]"
    exit 1
esac


#判断参数是否为空，为空则设为当前目录

#if [ -z "$1" ]; then

#     arg_dir=".";

#   else

#     arg_dir=$1"/.";

#fi

#echo "输入参数："$arg_dir

path=$( cd $( dirname ./ );pwd );

echo "查找目录："$path;

traverse $path
